﻿using Microsoft.Practices.EnterpriseLibrary.Validation.Validators;
using Mvc.Validation;
using Mvc.Validation.Validators;

namespace ValidationSample.Models
{
    public class User
    {
        [RegularExpressionValidatorAttribute(
            MessageTemplate = "Login name can only contain letters and numbers",
            ClientFunctionName = "alphanumeric",
            Pattern = ValidationUtils.AlphaNumericPattern)]
        [NotNullOrEmptyValidator(MessageTemplate = "Login name is required")]
        [StringLengthValidator(6, 50,
            MessageTemplate = "Login name must have at least {3} characters")]
        [RemoteValidator(IsPost=true, ServerMethod="/check",
            ValidatorType = typeof(LoginNameValidator),
            MessageTemplate = "Login name already exists")]
        public string LoginName { get; set; }

        [NotNullOrEmptyValidator(MessageTemplate = "Password is required")]
        [StringLengthValidator(6, 50,
            MessageTemplate = "Password must have at least {3} characters")]
        public string Password { get; set; }

        [NotNullOrEmptyValidator(MessageTemplate = "Retyped password is required")]
        [StringLengthValidator(6, 50,
            MessageTemplate = "Retyped password must have at least {3} characters")]
        [PropertyComparisonValidator("Password", ComparisonOperator.Equal,
            MessageTemplate = "Passwords must match")]
        [ClientID("password2")]
        public string RePassword { get; set; }

        [RegularExpressionValidatorAttribute(
            MessageTemplate = "Invalid email address",
            ClientFunctionName = "email",
            Pattern = ValidationUtils.EmailPattern)]
        public string Email { get; set; }

        [RegularExpressionValidatorAttribute(
            MessageTemplate = "Invalid website address",
            ClientFunctionName = "url2",
            Pattern = ValidationUtils.UrlPattern)]
        public string Website { get; set; }
        
        [NotNullOrEmptyValidator(MessageTemplate = "Location is required")]
        public string Location { get; set; }
    }
}
